package servlet.rool;

import net.sf.json.JSONObject;
import pojo.Role;
import service.AdRossService;
import service.AdminService;
import service.RoleService;
import service.impl.AdRossServiceImpl;
import service.impl.AdminServiceImpl;
import service.impl.RoleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 用户删除的servlet
 */
@WebServlet(value = "/AdminDeleServlet")
public class AdminDeleServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        AdminService as=new AdminServiceImpl();
        AdRossService ars=new AdRossServiceImpl();
        RoleService rs=new RoleServiceImpl();
        Role role=rs.queryOneRole(Integer.parseInt(request.getParameter("id")));
        JSONObject json=new JSONObject();
        if(role.getRoId()!=1){
            int bo=as.deleAdmin(Integer.parseInt(request.getParameter("id")));
            int bo2=ars.deleUrass(Integer.parseInt(request.getParameter("id")));
            if(bo>0 && bo2>0){
                json.put("msg","删除成功");
            }else {
                json.put("msg","删除失败");
            }
        }else{
            json.put("msg","无权限");
        }
        PrintWriter out=response.getWriter();
        out.print(json);
    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
        doGet(request, response);
    }
}
